package dfs;

import java.util.*;

/**
 * @author le
 */
public class SearchPath
{
    /**
     * 树的形状
     *      1
     *    2   3
     *      5
     */
    public static TreeNode treeNode = new TreeNode(1,new TreeNode(2,new TreeNode(),new TreeNode(5)),new TreeNode(3));

    public static int[] nums = {-10,-3,0,5,9};

    public static List<Integer> list = new ArrayList<>();

    public static void main(String[] args)
    {
        int slow = 0;
        int fast = 0;
        Queue<Integer> queue = new LinkedList<>();
        System.out.println(treeNode.val);
        queue.add(treeNode.val);
        fast++;

        while(slow < fast){
            System.out.println(queue.element());
            fast++;
            if (treeNode.left != null){
                queue.add(treeNode.left.val);
                slow++;
            }
            if (treeNode.right != null){
                queue.add(treeNode.right.val);
                slow++;
            }
        }


    }

    public static List<String> binaryTreePaths(TreeNode treeNode){

        List<String> paths = new ArrayList<>();
        constructPaths(treeNode,"",paths);
        return paths;
    }

    /**
     * 找出二叉树的每个通路
     * @param root
     * @param path
     * @param paths
     */
    public static void constructPaths(TreeNode root, String path, List<String> paths){
        if (root != null){
            StringBuffer buffer = new StringBuffer(path);
            buffer.append(Integer.toString(root.val));
            if (root.left == null && root.right == null){
                paths.add(buffer.toString());
            }else{
                buffer.append("->");
                constructPaths(root.left,buffer.toString(),paths);
                constructPaths(root.right,buffer.toString(),paths);
            }
        }
    }

    public static void stairShow(TreeNode root){
        int slow = 0;
        int fast = 0;
        Queue<Integer> queue = new LinkedList<>();
        queue.add(root.val);
        fast++;

    }



}
